import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Spikes here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Spikes extends Trap
{
    private int skinIndex;
    
    public Spikes(int x,int del,int iniD)
    {
        super(x,del,iniD);
        
        damage=10;
        
        skinIndex=0;
        
        GreenfootImage image=new GreenfootImage("spikes0.png");
        image.setTransparency(0);
        setImage(image);
        
    }
    
    public void act() 
    {
        timer.tick();
        activeTimer.tick();
        
        if(active==true || !activeTimer.wait(initialDelay))     
        activeImage();
        if(active==false)
        return;
        
        GameWorld world=(GameWorld)getWorld();
        
        if(skinIndex!=6)
        setLocation(world.getScrollx()+360+posX,world.getHeight()-80-getImage().getHeight()/2);
        else
        setLocation(world.getScrollx()+360+posX,world.getHeight());
        
        if(skinIndex<6)
        {
            if(!timer.wait(50))
            {
                skinIndex++;
                
                switch(skinIndex)
                {
                    case 0:     setImage(new GreenfootImage("spikes0.png"));
                                break;
                    case 1:     setImage(new GreenfootImage("spikes1.png"));
                                break;
                    case 2:     setImage(new GreenfootImage("spikes2.png"));
                                break; 
                    case 3:     setImage(new GreenfootImage("spikes3.png"));
                                break;
                    case 4:     setImage(new GreenfootImage("spikes2.png"));
                                break;
                    case 5:     setImage(new GreenfootImage("spikes1.png"));
                                break;
                    default:    setImage(new GreenfootImage(10,10));
                                break;
                }
            }
        }
        else
            if(!timer.wait(delay))
            skinIndex=0;
            
            
        if(isTouchingPlayer() && skinIndex!=0)
        ((GameWorld)getWorld()).getPlayer().getHurt(10);

    }      
}
